package com.mengtian_tech.tju.dataquery.api.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mengtian_tech.tju.dataquery.api.util.ResponseUtil;

@RestController
@RequestMapping("/api/person")
public class PersonGateController {

	@Autowired
	@Qualifier("jdbcTemplateDataAi")
	JdbcTemplate jdbcTemplateDataAi;

	@RequestMapping("rpt1")
	public Object rpt(String begin, String end, String school) throws ParseException {

		// 获取请假数量
		List<Map<String, Object>> list = this.jdbcTemplateDataAi.queryForList(
				"SELECT date_on,sum(user_count) cnt from rpt_user_gate where date_on >=? and date_on <= ?"
				+ " and school_area like ? group by date_on  order by date_on asc",
				begin, end,school+"%");
 
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("rpt", list);
 
		return ResponseUtil.ok(result);
	}
	
	@RequestMapping("rpt2")
	public Object rpt2(String begin, String end, String school) throws ParseException {
		 

		// 获取请假数量
		List<Map<String, Object>> list2 = this.jdbcTemplateDataAi.queryForList(
				"select sum(user_count)  cnt , school_area, gate_name from rpt_user_gate "
				+ " where  date_on >=? and date_on <= ?  and school_area like ? "
				+ " group by school_area,gate_name",
				begin, end,school+"%");

		Map<String, Object> result = new HashMap<String, Object>();
		 
		result.put("rpt", list2);

		return ResponseUtil.ok(result);
	}

}
